<template>
  <a-modal v-model="visible" :width="1080" title="分销员">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="12" :lg="12" :md="12" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号">
              <a-input placeholder="请输入手机号" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户身份">
              <a-select v-model="queryParam.level" @change="searchQuery">
                <a-select-option v-for="(item3,index3) in levelList" :key="index3" :value="item3.level">
                  {{item3.name}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="12" :lg="12" :md="12" :sm="24">
            <a-form-item label="注册时间">
              <a-range-picker format="YYYY-MM-DD" :placeholder="['开始时间', '结束时间']" @change="onDateChange" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" bordered rowKey="id" :columns="queryParam.type==3?columns1:columns" :dataSource="dataSource"
        :pagination="ipagination" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="userSlot" slot-scope="text,record">
          <div style="display:flex;align-items: center;">
            <img :src="record.headUrl" style="width:50px;height:50px;">
            <div style="padding-left:5px;">
              <div>{{record.nickname}}</div>
              <div>{{record.phone}}</div>
              <div>注册时间：</div>
              <div>{{record.createTime}}</div>
            </div>
          </div>
        </template>
        <template slot="repSlot" slot-scope="text,record">
          <div>
            <span>积分：{{record.integral}}</span>
            <a-divider type="vertical" />
            <a @click="addIntegral(record.id)">加积分</a>
            <a-divider type="vertical" />
            <a @click="subIntegral(record)">减积分</a>
          </div>
          <div>余额：{{record.balance}}</div>
          <div>订单数量：{{record.orderNum}}</div>
          <div>支付金额：{{record.orderAmount}}</div>
        </template>

        <template slot="propSlot" slot-scope="text,record">
          <div>身份：{{record.role==0?'普通用户':'vip会员'}}</div>
          <div>类型：{{(record.isCompany==1||record.isMember==1)?'企业用户':'个人用户'}}</div>
          <div>性别：{{record.sex_dictText}}</div>
          <div>生日：{{record.dateBirth?record.dateBirth:'未知'}}</div>
          <div>地区：{{record.full_address}}</div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <!--标签和分组信息展示-->
        <template slot="crmTags" slot-scope="text,record">
          <div v-for="(item,index) in record.crmTags" :key="index" style="margin-bottom:2px;">
            <a-tag :color="item.type==1?'#87d068':'#108ee9'">
              {{item.name}}
            </a-tag>
          </div>
        </template>

        <template slot="crmGroups" slot-scope="text,record">
          <div v-for="(item,index) in record.crmGroups" :key="index" style="margin-bottom:2px;">
            <a-tag>
              {{item.name}}
            </a-tag>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="goInfo(record)">
            查看
          </a>
        </span>

      </a-table>
    </div>

  </a-modal>
</template>

<script>
import { putAction, getAction, postAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'

import JDate from '@/components/jeecg/JDate.vue'

export default {
  name: 'YymsGoodList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
  },
  data () {
    return {
      pageCheckedKeys: [],
      noPageCheckedKeys: [],
      pageCheckedRows: [],
      noPageCheckedRows: [],
      visible: false,
      description: '分销员',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '昵称',
          align: "left",
          dataIndex: 'nickname'
        },
        {
          title: '手机号',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '上级用户昵称',
          align: "left",
          dataIndex: 'parentNickname'
        },

        {
          title: '用户等级',
          align: "center",
          dataIndex: 'levelName'
        },
        {
          title: '下级数',
          align: "right",
          dataIndex: 'childNum'
        },

        {
          title: '累计佣金',
          align: "right",
          dataIndex: 'sumAmount'
        },
        {
          title: '等级更新时间',
          align: "center",
          dataIndex: 'updateLevelTime'
        },
        {
          title: '身份渠道',
          align: "center",
          dataIndex: 'channel',
          customRender: function (text) {
            return text == 1 ? '线上买礼包' : text == 3 ? '后台变更身份' : '任务升级'
          }
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      columns1: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '昵称',
          align: "left",
          dataIndex: 'nickname'
        },
        {
          title: '手机号',
          align: "center",
          dataIndex: 'phone'
        },

        {
          title: '开单数',
          align: "center",
          dataIndex: 'orderNum'
        },
        {
          title: '消费金额',
          align: "right",
          dataIndex: 'orderAmount'
        },

        {
          title: '累计佣金',
          align: "right",
          dataIndex: 'sumAmount'
        },
        {
          title: '注册时间',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '最近登录时间',
          align: "center",
          dataIndex: 'loginTime'
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/tipMember/childList"
      },
      dictOptions: {},
      levelList: []
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    getLevels () {
      var that = this
      getAction("/mallPlus/hmsHandConfig/list", {}).then((res) => {
        if (res.success) {
          that.levelList = res.result.records
        }
      })
    },
    open (pid, type) {
      if (pid) {
        this.queryParam['parentId'] = pid
      }
      if (type) {
        this.queryParam['type'] = type
      }
      this.loadData()
      this.getLevels()
    },
    searchReset () {
      this.queryParam = {
        parentId: this.queryParam.parentId,
        type: this.queryParam.type
      }
      this.loadData(1)
    },
    goInfo (record) {
      this.$router.push({ path: '/hand/user/memberinfo', query: { id: record.id } })
    },
    setSelected () {

    },
    initDictConfig () {
    }
  }
}
        </script>
<style scoped>
@import '~@assets/less/common.less';
</style>
